package com.chlitina.store.modules.sms.utils;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

import com.chlitina.store.common.config.Global;

public class SmsUtils {
	final public static String SMS_RECHARGE_RATE = "SET_SMS_RECHARGE_RATE";//短信充值费率
	final public static int intervalTime = 10;//延迟时间
	final public static int default_length = 64;//一条短信的默认长度
	
	final public static int CARE_TIP_DAYS = 1;//护理到期提前提醒时间
	final public static int PRODUCT_TIP_DAYS = 3;//产品到期提前提醒时间
	final public static int BALANCE_TIP_NUMS = 200;//产品到期提前提醒时间
	final public static int send_begin_time = 14;//短信发送初始时间
	final public static int send_end_time = 17;//短信发送结束时间
	
	public static String getSmsTotalReamin() {
		HttpClient client = new HttpClient();
		String restMsg = "";
		GetMethod get = null;
		try {
			get = new GetMethod(
					"http://sms.webchinese.cn/web_api/SMS/?Action=SMS_Num&Uid="
							+ Global.getConfig("sms.accessKeyId") + "&Key="
							+ Global.getConfig("sms.accessKeySecret"));
			int status = client.executeMethod(get);
			if (status == 200) {
				restMsg = get.getResponseBodyAsString();
			}
			get.releaseConnection();
		} catch (Exception e) {
			if (get != null) {
				get.releaseConnection();
			}
			System.out.println("查询异常");
		}
		return restMsg;
	}	
	public static Calendar getPlanSendTime(boolean isSend){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		if (!isSend) {
			try {
				int hour = calendar.get(Calendar.HOUR_OF_DAY);
				if (hour > send_end_time) {
					calendar.add(Calendar.DAY_OF_MONTH, 1);
					calendar.set(Calendar.HOUR_OF_DAY, send_begin_time);
					calendar.set(Calendar.MINUTE, 0);
					calendar.set(Calendar.SECOND, 0);
				}
				if (hour < send_begin_time) {
					calendar.set(Calendar.HOUR_OF_DAY, send_begin_time);
					calendar.set(Calendar.MINUTE, 0);
					calendar.set(Calendar.SECOND, 0);
				}
			} catch (Exception e1) {
			}
		}
		calendar.add(Calendar.SECOND, intervalTime);
		return calendar;
	}
	public static void main(String[] args) {
		getPlanSendTime(false);
	}
}
